<?php

require_once 'ActionFramework/start.php';
require_once 'views/all.cls.php';

/**
 * Save the criteria and return to the edit criteria view.
 */
class ResetPasswordAction extends LoginByUrlAction {
	
	const INPUT_PASSWORD = 'password';
	
	public function __construct() {
		parent::__construct();
		$this->add_input(new TextInput(ResetPasswordAction::INPUT_PASSWORD, 'Password'));
	}
	
	public function redirect_valid_credentials(Array $request) {
		$user = $_SESSION['user'];
		
		$user->password = $request[ResetPasswordAction::INPUT_PASSWORD];
		global $DB;
		$DB->save_user($user);
				
		$view = new EditProfileView($user);
		$view->add_message("New password saved");
		return $view;
	}
	
}

?>